package cn.jbolt.wechat.admin.user;

import cn.jbolt.core.api.JBoltApiBaseController;
import cn.jbolt.core.api.httpmethod.JBoltHttpGet;
import cn.jbolt.core.api.httpmethod.JBoltHttpPost;
import cn.jbolt.core.model.base.JBoltBaseModel;
import cn.jbolt.core.permission.CheckPermission;
import cn.jbolt.core.permission.UnCheck;
import cn.jbolt.core.service.base.JBoltBaseService;
import cn.jbolt.extend.permission.PermissionKey;
import cn.jbolt.wechat.service.JBoltWechatUserService;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.core.Path;
import com.jfinal.plugin.activerecord.tx.Tx;
/**
 * 微信用户信息_模板表
 * @ClassName: WechatUserAdminController
 * @author: 山东小木
 * @date: 2023-10-13 16:15
 */
@Path("/api/admin/wechatUser")
@CheckPermission(PermissionKey.WECHAT_USER)
public class WechatUserAdminController extends JBoltApiBaseController {

	@Inject
	private JBoltWechatUserService service;
	@Override
    protected JBoltBaseService<? extends JBoltBaseModel<?>> getModelService() {
        return service;
    }
   /**
    * 单个详情
    */
   @JBoltHttpGet
   public void index() {
       renderJBoltApiRet(findModelById());
   }
   /**
	* 数据源
	*/
	@JBoltHttpGet
	@JBoltHttpPost
	@Before(WechatUserArgValidator.class)
	public void datas() {
		renderJBoltApiSuccessWithData(
				service.getAdminDatas(getLong(0),
					getPageNumber(), getPageSize(),
					getKeywords(),
					getInt("sex"),
					getSortColumn("id"),
					getSortType("desc"),
					getBoolean("subscribe"),
					getBoolean("isChecked"),
					getBoolean("enable"))
		);
	}
   /**
	* 删除
	*/
	@Before({Tx.class, WechatUserArgValidator.class})
    @JBoltHttpGet
	public void delete() {
	    renderJBoltApiRet(service.delete(getLong(0),getLong(1)));
	}


	/**
	 * 切换启用状态
	 */
	@Before({Tx.class, WechatUserArgValidator.class})
	public void toggleEnable() {
		renderJBoltApiRet(service.toggleEnable(getLong(0), getLong(1)));
	}

   /**
	* autocomplete组件专用数据
	*/
	@UnCheck
	@Before(WechatUserArgValidator.class)
	public void autocompleteDatas() {
        renderJBoltApiSuccessWithData(service.getAutocompleteList(getLong(0), get("q"), getInt("limit",20),true,"nickname"));

	}

	@Before(WechatUserArgValidator.class)
	public void sync() {
		Long mpId=getLong(0);
		renderJBoltApiRet(service.sync(mpId));
	}

	/**
	 * 同步个人信息
	 */
	@Before(WechatUserArgValidator.class)
	public void syncUser() {
		Long mpId=getLong(0);
		Long id=getLong(1);
		renderJBoltApiRet(service.syncOneUserInfo(mpId,id));
	}
}
